<template>
<div class="wrap">
    <button @click="user">我的书架</button>
    <list v-for="item in list" :key="item.id" :item="item" @babeil="babeil"></list>
</div>
</template>

<script>
import List from "@/components/list"
export default {
    components:{
        List
    },
    data(){
        return {
            list:[],
        }
    },
    created(){ 
        this.$http.get("/list").then(res => {
            
            this.list = res.data.data.map((ele) => {
                if(ele.status != 'false'){
                    ele.status = true
                }
                return ele
            })
        });
        this.$bus.$on("add",(data) => {
            let ind = this.list.findIndex(ele => {
               return ele.id == data.id
            })
            if(ind != -1){
                this.$http.get("/insert",{params:{id:data.id,status:data.status}}).then(res=>{
                    this.list = res.data.data.data.map((ele) => {
                            if(ele.status != 'false'){
                                ele.status = true
                            }
                            return ele
                    })

                    console.log(res.data.data)
                })
            }
        })
    },
    methods:{
        babeil(data){
            this.$router.push({name:"babeil",params:{id:data.id}})
        },
        user(){
            this.$router.push({path:"/user"})
        }
    }
}
</script>

<style>

</style>
